package cc.rboot.feature.resolver;

import cc.rboot.feature.core.AbstractFeatureResolver;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class TimeFeatureResolver extends AbstractFeatureResolver {

    @Override
    public boolean notIn(String[] conditions) {
        return false;
    }

    @Override
    public boolean in(String[] conditions) {
        return false;
    }

    @Override
    public boolean equals(String condition) {
        LocalDateTime time = LocalDateTime.parse(condition);
        final LocalDateTime now = LocalDateTime.now();

        return now.isEqual(time);
    }

    @Override
    public boolean greaterThan(String condition) {
        LocalDateTime time = LocalDateTime.parse(condition);
        final LocalDateTime now = LocalDateTime.now();
        return now.isAfter(time);
    }

    @Override
    public boolean lessThan(String condition) {
        LocalDateTime time = LocalDateTime.parse(condition);
        final LocalDateTime now = LocalDateTime.now();
        return now.isBefore(time);
    }

    @Override
    public boolean between(String[] conditions) {
        LocalDateTime beginTime = LocalDateTime.parse(conditions[0]);
        LocalDateTime endTime = LocalDateTime.parse(conditions[1]);
        final LocalDateTime now = LocalDateTime.now();

        return now.isAfter(beginTime) && now.isBefore(endTime);
    }
}
